package hngc.com;

import javax.security.auth.login.LoginException;
import java.util.Scanner;

public class Box9 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        boolean name = false;
        System.out.println("请输入用户名：");
        String username = scanner.next();
        System.out.println("请输入密码：");
        String password = scanner.next();
        try {
            if (username.length() == 8 && username.length() < 9) {
                for (int i = 0; i < username.length(); i++) {
                    char ch = username.charAt(i);//获取每个字符
                    if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'B')) {    //判断字符是否为的字符
                        name = true;
                    } else {
                        name = false;
                        //如果字符的字母，则抛出LoginException异常
                        throw new LoginException("用户名错误");
                    }
                }
            } else {
                throw new LoginException("用户名错误");
            }if (name) {
                if (password.length()>=6){
                    for (int i=0;i<password.length();i++){
                        char ch = password.charAt(i);
                        if (ch >= '0' && ch <= '9'){
                        }else {
                            //如果字符不是0~9的数字，则抛出LoginException异常
                            throw new LoginException("密码错误");
                        }
                    }
                }else {
                    throw new LoginException("密码错误");
                }
                System.out.println("用户名密码正确");
            }
        }catch (LoginException e){
            System.out.println(e.getMessage());
        }
        scanner.close();
    }
}
